package com.ushine.design.design.b_structural_type.c_composite.b_example;

import java.util.ArrayList;

public class Folder extends AbstactFile {
    //定义集合，存储AbstractFile类型的成员
    private ArrayList<AbstactFile> abstactFiles = new ArrayList<>();

    private String name;

    public Folder() {
    }

    public Folder(String name) {
        this.name = name;
    }

    @Override
    public void add(AbstactFile file) {
        abstactFiles.add(file);
    }

    @Override
    public void remove(AbstactFile file) {
        abstactFiles.remove(file);
    }

    @Override
    public AbstactFile getChild(int i) {
        return abstactFiles.get(i);
    }

    @Override
    public void killVirus() {
        System.out.println("----对文件夹'" + name + "'进行杀毒。");
        abstactFiles.forEach(abstactFile -> {
            abstactFile.killVirus();
        });
    }

}
